package gases.as3.librarys.components.skin.transform
{
	public class TransformXML extends BaseTransform
	{
		private const namespace_uri:String = "gases.compnents.ui.skin";
		
		public function TransformXML()
		{
		}
		
		override public function resloveConfig(config:Object):Object
		{
			var data:Object;
			if(config is XML)
			{
				data = reslove(XML(config));
			}
			return data;
		}
		
		private function reslove(xml:XML):Object
		{
			var config:Object = new Object();
			var leng1:int = xml.children().length();
			for(var i:int = 0; i < leng1; i++)
			{
				var itemXML:XML = xml.children()[i];
				var attributes:XMLList = itemXML.attributes();
				var item:Object = new Object();
				var leng2:int = attributes.length();
				for(var j:int = 0; j < leng2; j++)
				{
					var nm:String = attributes[j].name();
					var value:Object = attributes[j].toString();
					item[nm] = value;
				}
				
				item.styles = resloveStyles(itemXML);
//				获取LOCALNAME就是SKIN:BUTTON 后面的BUTTON
//				var type:String = itemXML.localName();
//				item["type"] = type;
				var name:String = itemXML.@skinname;
				config[name] = item;
			}
			return config;
		}
		
		private function resloveStyles(itemXML:XML):Array
		{
			var list:Array = [];
			var stylesXmls:XMLList = itemXML.children();
			var leng:int = stylesXmls.length();
			for(var i:int = 0; i < leng; i++)
			{
				var styleXml:XML = stylesXmls[i];
				var attributes:XMLList = styleXml.attributes();
				var item:Object = new Object();
				var leng2:int = attributes.length();
				for(var j:int = 0; j < leng2; j++)
				{
					var nm:String = attributes[j].name();
					var value:Object = attributes[j].toString();
					item[nm] = value;
				}
				list.push(item);
			}
			return list;
		}
	}
}

